/**
 * @Author: easten
 * @Created: 2024-07-25 10:34:44
 * @Description: 登录相关的接口
 *
 */
import {
  Login,
  LoginForm,
  LoginUserInfo,
  Logout,
  PhoneLoginForm,
  ReqPhoneValidCode,
  ReqValidCode,
} from "_common/DataType";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

export class ApiAuth {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/sys/auth/";

  /**
   * @description 构造函数
   * @param {AxiosInstance} instance
   * @memberof ApiAuth
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 用户登录 */
  login(params: LoginForm) {
    return this.request.post<Login>(this.url + "login", params, {
      loading: false,
    }); // 正常 post json 请求  =  application/json
  }
  /** 获取验证码 */
  picCaptcha() {
    return this.request.get<ReqValidCode>(this.url + "getPicCaptcha", {});
  }
  /** 用户退出登录 */
  logout(params: Logout) {
    return this.request.post(this.url + "logout", params);
  }
  /** 获取用户信息 */
  getLoginUser() {
    return this.request.get<LoginUserInfo>(this.url + "get-login-user", {});
  }
  /** 获取短信验证码 */
  getPhoneValidCode(params: ReqPhoneValidCode) {
    return this.request.get<string>(this.url + "getPhoneValidCode", params);
  }

  /** 手机号登录 */
  loginByPhone(params: PhoneLoginForm) {
    return this.request.post<Login>(this.url + "loginByPhone", params);
  }
}
